/**
 * @Author YuanYuan
 * @Date 2022/9/11
 * @Time 10:58
 */

class Counter {
    public int count = 0;
    public synchronized void increase() {
        count++;
    }
}
public class TestDemo {
    public static void main(String[] args) throws InterruptedException {
        Counter counter = new Counter();
        Thread thread = new Thread(()-> {
            for (int i = 0; i < 5_0000; i++) {
                counter.increase();
            }
        });
        Thread thread1 = new Thread(()-> {
            for (int i = 0; i < 5_0000; i++) {
                counter.increase();
            }
        });
        thread.start();
        thread1.start();

        thread.join();
        thread1.join();

        System.out.println("counter :" + counter.count);
    }
}
